<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:template match="response" mode="cp-path">
		<xsl:param name="activeLink" />
		<xsl:param name="cnt" select="count(object[@type='cp_item'])" />
		
		<div id="favorite_link" class="favorite">
			<a href="/">избранное</a>
		</div>
				
		<div class="links">
			<xsl:if test="$cnt = 0">
				<xsl:text>Начало</xsl:text>
			</xsl:if>
			<xsl:if test="$cnt != 0">
				<a href="{$baseURI}/admin/cp">Начало</a>
				<xsl:text> → </xsl:text>
				<xsl:apply-templates select="object[@type='cp_item']" mode="path">
					<xsl:with-param name="activeLink" select="$activeLink" />
					<xsl:with-param name="cnt" select="$cnt" />
				</xsl:apply-templates>
			</xsl:if>
		</div>
	</xsl:template>
	
	<xsl:template match="object[@type='cp_item']" mode="path">
		<xsl:param name="activeLink" />
		<xsl:param name="cnt" />
		<xsl:param name="itemModule" select="property[@name='link_module']/value" />
		<xsl:param name="itemMethod" select="property[@name='link_method']/value" />
		
		<xsl:choose>
			<xsl:when test="position() = $cnt and $activeLink != 1">
				<xsl:value-of select="property[@name='title']/value" />
			</xsl:when>
			<xsl:otherwise>
				<a>
					<xsl:attribute name="href">
						<xsl:choose>
							<xsl:when test="$itemModule != ''">
								<xsl:value-of select="concat($baseURI, '/admin/', $itemModule)" />
								
								<xsl:if test="$itemMethod != ''">
									<xsl:value-of select="concat('/', $itemMethod)" />
								</xsl:if>
							</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="concat($baseURI, '/admin/cp/dir/', @id)" />
							</xsl:otherwise>						
						</xsl:choose>
					</xsl:attribute>
					<xsl:value-of select="property[@name='title']/value" />
				</a>
			</xsl:otherwise>
		</xsl:choose>
		
		<xsl:if test="position() != $cnt">
			<xsl:text> → </xsl:text>
		</xsl:if>
	</xsl:template>
	
</xsl:stylesheet>